package com.example.feign.controller;

import com.example.feign.pojo.Product;
import com.example.feign.service.ProductService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@RefreshScope
@Controller
public class ProductController {

    @Resource
    ProductService productService;

    @Value("${version}")
    String version;

    @Value("${server.port}")
    String port;


    @RequestMapping("/products")
    public Object products(Model m){
        List<Product> products = productService.listProducts();
        m.addAttribute("ps",products);
        m.addAttribute("version",version);
        m.addAttribute("port",port);
        return "products";
    }
}
